package com.demo.reservation.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.IService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.demo.reservation.domain.PetInfo;
import com.demo.reservation.mapper.PetInfoMapper;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

@Service
public class PetInfoService extends ServiceImpl<PetInfoMapper, PetInfo> {
    public PetInfo create(PetInfo pet) {
        QueryWrapper q = new QueryWrapper();
        if(pet.getUid() > 0) {
            q.eq("uid", pet.getUid());
        }
        if (StringUtils.hasLength(pet.getName())) {
            q.eq("name", pet.getName());
        }
        if (StringUtils.hasLength(pet.getCategory())) {
            q.eq("category", pet.getCategory());
        }
        PetInfo one = getOne(q);
        if (null == one) {
            save(pet);
            return pet;
        }
        return one;
    }
}
